package com.bjsxt.messageConsumer.listener;

import com.bjsxt.livegoods.pojo.LivegoodsMessage;
import com.bjsxt.messageConsumer.service.BuyactionService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName : LivegoodsBuyactionConsumer
 * @Description :购买消息消费者
 * @Author : ZWZ
 * @Date: 2021/8/27 16:15
 */
@Component
public class LivegoodsBuyactionConsumer {

    @Autowired
    private BuyactionService buyactionService;

    /**
     * 购买消息消费者
     *
     * @param livegoodsMessage
     * @return
     */
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "${livegoods.rabbit.buy.queue}", autoDelete = "false"),
                    exchange = @Exchange(name = "${livegoods.rabbit.buy.exchange}"),
                    key = "${livegoods.rabbit.buy.routingKey}"
            )
    })
    public Object onMessage(LivegoodsMessage livegoodsMessage) {
        String phone = livegoodsMessage.getPhone();
        String itemId = livegoodsMessage.getItemId();
        return buyactionService.buyaction(itemId, phone);
    }

}
